home *** CD-ROM | disk | FTP | other *** search
- /*
- File: LinkSpec.cpp
-
- Contains: Implementation for ODLinkSpec class.
-
- Owned by: Craig Carper
-
- Copyright: © 1993 - 1995 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <14> 10/8/95 TJ Fixes Recomended by Refball
- <13> 8/16/95 NP 1274946: ErrorDef.idl problems. Add include
- file.
- <12> 8/12/95 TÇ 1276812 Need to use TempObjs and TempRefs
- for exception safety and to avoid TRY
- blocks, 1276807 Opt./Bug: use StdTypIO
- routines for portable streaming & smaller
- footprint
- <11> 8/3/95 RR #1257260: Collapse B classes. Remove
- somInit methods. Don't call IsInitialized
- or SubclassResponsibility
- <10> 5/26/95 VL 1251403: Multithreading naming support.
- <9> 4/27/95 CC 1242555: GetOriginatingProcessID: Removed
- obsolete $5 comment.
- <8> 3/10/95 CC 1225926: Fixed typo in FromThisDraft().
- <7> 1/27/95 TJ Changed ODAppleEvent to AppleEvent.
- <6> 12/20/94 VL 1195012: Make Storage calls be
- marshallable.
- <5> 12/15/94 CC 1205709 LinkSpec.cpp - Removed AcquirePart(),
- GetData(), and GetDataSize() methods;
- changed ReadLinkSpec(), WriteLinkSpec(),
- ReadFromAppleEvent(), and
- WriteToAppleEvent().
- <4> 12/8/94 CC 1203864 WriteToAppleEvent: changed &_fData
- to _fData, to copy the link data correctly.
- <3> 9/15/94 CC 1186775 - Added SOM_CATCH to
- FromThisDraft(); Return som error from
- WriteToAppleEvent().
- <2> 7/27/94 CC Removed GetProcessLaunchDate, added
- FromThisDraft, changed GetProcessID to
- GetOriginatingProcessID.
- <1> 6/21/94 CC first checked in
-
- ------------------- CC ---- Converted to SOM
-
- <2> 5/9/94 MB #1162181: Changes necessary to install MMM.
- <1> 3/25/94 CC first checked in
-
- ------------------- CC ---- Moved from Core to Storage subsystem
-
- <3> 3/24/94 CC Changed WriteToProperty() to
- WriteLinkSpec(), ReadFromProperty() to
- ReadLinkSpec() (1153049); write version in
- WriteToAppleEvent().
- <2> 3/15/94 MB Changes to support SCpp/ASLM builds,
- #1150864.
- <2> 2/8/94 TÇ Throw -> THROW & some code clean up
- <1> 1/21/94 CC first checked in
- <4> 12/21/93 VL Changed XMPStorageUnit::GetValueSize to
- StorageUnit::GetSize.
- <3> 12/8/93 CC Added WriteToAppleEvent,
- ReadFromAppleEvent, and accessors for
- fields.
- <2> 12/3/93 TÇ Stop including XMPError.h, it is included
- as ErrorDef.h inside Except.h
- <1> 11/15/93 CC first checked in
- To Do:
- */
-
- #define VARIABLE_MACROS
-
- #define ODLinkSpec_Class_Source
- #include <LinkSpec.xih>
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include "StdProps.xh"
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdTypes_defined
- #include "StdTypes.xh"
- #endif
-
- #ifndef SOM_ODDraft_xh
- #include "Draft.xh"
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include "StorageU.xh"
- #endif
-
- #ifndef _EXCEPT_
- #include "Except.h"
- #endif
-
- #ifndef _ODMEMORY_
- #include "ODMemory.h"
- #endif
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- #ifndef _BARRAY_
- #include <BArray.h>
- #endif
-
- #ifndef _STDTYPIO_
- #include <StdTypIO.h>
- #endif
-
- #ifndef _TEMPOBJ_
- #include <TempObj.h>
- #endif
-
- #ifndef _STORUTIL_
- #include <StorUtil.h>
- #endif
-
- #ifndef _UTILERRS_
- #include "UtilErrs.h"
- #endif
-
- #pragma segment ODLinkSpec
-
- //==============================================================================
- // Constants
- //==============================================================================
- const ODULong kLinkSpecVersion = 1; // Second version
-
- // •••• kODSourcePartKey also defined for Drag & Drop ••••
- // •••• These don't belong here ••••
- #define kODProcessLaunchDateKey 'pldt'
- #define kODSourcePartKey 'part'
- #define kODLinkSpecDataKey 'data'
- #define kODLinkSpecDataSizeKey 'size'
- #define kODLinkSpecVersionKey 'vers'
-
- //==============================================================================
- // ODLinkSpec
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // ODLinkSpec::somUninit
- //------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODLinkSpecsomUninit(ODLinkSpec *somSelf)
- {
- /* ODLinkSpecData *somThis = ODLinkSpecGetData(somSelf); */
- ODLinkSpecMethodDebug("ODLinkSpec","somUninit");
-
- parent_somUninit(somSelf);
- }
-
- //------------------------------------------------------------------------------
- // ODLinkSpec::InitLinkSpec
- //------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODLinkSpecInitLinkSpec(ODLinkSpec *somSelf, Environment *ev,
- ODPart* part,
- ODByteArray* partData)
- {
- ODLinkSpecData *somThis = ODLinkSpecGetData(somSelf);
- ODLinkSpecMethodDebug("ODLinkSpec","InitLinkSpec");
-
- SOM_CATCH return;
-
- /* Moved from somInit. SOM itself sets fields to zero
- _fProcessLaunchDate = 0;
- */
- _fProcessID.lowLongOfPSN = kNoProcess;
- _fProcessID.highLongOfPSN = 0;
-
- somSelf->InitBaseLinkSpec(ev, part, partData);
-
- if ( part )
- {
- ProcessSerialNumber psn;
- ProcessInfoRec myProcessInfo;
-
- psn.lowLongOfPSN = kCurrentProcess;
- psn.highLongOfPSN = 0;
- myProcessInfo.processAppSpec = NULL;
- myProcessInfo.processName = NULL;
- myProcessInfo.processInfoLength = sizeof(myProcessInfo);
-
- OSErr error = GetProcessInformation(&psn, &myProcessInfo);
- ASSERT((error == 0), kODErrAssertionFailed);
-
- _fProcessID = myProcessInfo.processNumber;
- _fProcessLaunchDate = myProcessInfo.processLaunchDate;
- }
- }
-
- //------------------------------------------------------------------------------
- // ODLinkSpec::FromThisDraft (OVERRIDE)
- //------------------------------------------------------------------------------
-
- SOM_Scope ODBoolean SOMLINK ODLinkSpecFromThisDraft(ODLinkSpec *somSelf, Environment *ev)
- {
- ODLinkSpecData *somThis = ODLinkSpecGetData(somSelf);
- ODLinkSpecMethodDebug("ODLinkSpec","FromThisDraft");
-
- SOM_CATCH return kODFalse;
-
- ProcessSerialNumber myPSN;
- ProcessInfoRec myProcessInfo;
- Boolean isSamePSN;
-
- myPSN.lowLongOfPSN = kCurrentProcess;
- myPSN.highLongOfPSN = 0;
- myProcessInfo.processAppSpec = NULL;
- myProcessInfo.processName = NULL;
- myProcessInfo.processInfoLength = sizeof(myProcessInfo);
- THROW_IF_ERROR(GetProcessInformation(&myPSN, &myProcessInfo));
- THROW_IF_ERROR(SameProcess(&_fProcessID, &myProcessInfo.processNumber, &isSamePSN));
-
- return (isSamePSN && (myProcessInfo.processLaunchDate == _fProcessLaunchDate));
- }
-
- //------------------------------------------------------------------------------
- // ODLinkSpec::GetOriginatingProcessID
- //------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODLinkSpecGetOriginatingProcessID(ODLinkSpec *somSelf, Environment *ev,
- ProcessSerialNumber *psn)
- {
- ODLinkSpecData *somThis = ODLinkSpecGetData(somSelf);
- ODLinkSpecMethodDebug("ODLinkSpec","GetProcessLaunchDate");
-
- ProcessInfoRec info;
-
- info.processAppSpec = NULL;
- info.processName = NULL;
- info.processInfoLength = sizeof(info);
-
- if ( (GetProcessInformation(&_fProcessID, &info) == noErr) &&
- (info.processLaunchDate == _fProcessLaunchDate) )
- {
- *psn = _fProcessID;
- }
- else
- {
- psn->lowLongOfPSN = kNoProcess;
- psn->highLongOfPSN = 0;
- ODSetSOMException(ev, kODErrCannotGetExternalLink);
- }
- }
-
- //------------------------------------------------------------------------------
- // ODLinkSpec::WriteLinkSpec (OVERRIDE)
- //------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODLinkSpecWriteLinkSpec(ODLinkSpec *somSelf, Environment *ev,
- ODStorageUnit* su)
- {
- ODLinkSpecData *somThis = ODLinkSpecGetData(somSelf);
- ODLinkSpecMethodDebug("ODLinkSpec","WriteLinkSpec");
-
- SOM_CATCH return;
-
- ODVolatile(su);
-
- ODULong version = kLinkSpecVersion;
- ODULong size;
-
- ODSUForceFocus(ev, su, kODNULL, kODLinkSpec);
- size = su->GetSize(ev);
- su->DeleteValue(ev, size);
-
- TRY
- StorageUnitSetValue(su, ev, sizeof(ODULong), (ODValue) &version);
- StorageUnitSetValue(su, ev, sizeof(ProcessSerialNumber), (ODValue) &_fProcessID);
- StorageUnitSetValue(su, ev, sizeof(ODULong), (ODValue) &_fProcessLaunchDate);
-
- parent_WriteLinkSpec(somSelf, ev, su);
- CATCH_ALL
- su->Remove(ev);
- RERAISE;
- ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // ODLinkSpec::ReadLinkSpec (OVERRIDE)
- //------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODLinkSpecReadLinkSpec(ODLinkSpec *somSelf, Environment *ev,
- ODStorageUnit* su)
- {
- ODLinkSpecData *somThis = ODLinkSpecGetData(somSelf);
- ODLinkSpecMethodDebug("ODLinkSpec","ReadLinkSpec");
-
- SOM_CATCH return;
-
- ODULong version;
- ProcessSerialNumber processID;
- ODULong processLaunchDate;
- ODULong valueSize;
-
- // Pre-focused property must contain a link spec value
- if (!ODSUExistsThenFocus(ev, su, (ODPropertyName) kODNULL, kODLinkSpec))
- THROW(kODErrNoLinkSpecValue);
-
- StorageUnitGetValue(su, ev, sizeof(ODULong), (ODValue) &version);
- if (version != kLinkSpecVersion)
- THROW(kODErrUnknownLinkSpecVersion);
-
- valueSize = StorageUnitGetValue(su, ev, sizeof(ProcessSerialNumber), (ODValue) &processID);
- if ( valueSize != sizeof(ProcessSerialNumber) )
- THROW(kODErrCorruptLinkSpecValue);
-
- valueSize = StorageUnitGetValue(su, ev, sizeof(ODULong), (ODValue) &processLaunchDate);
- if ( valueSize != sizeof(ODULong) )
- THROW(kODErrCorruptLinkSpecValue);
-
- parent_ReadLinkSpec(somSelf, ev, su);
-
- _fProcessID = processID;
- _fProcessLaunchDate = processLaunchDate;
- }
-
- //------------------------------------------------------------------------------
- // ODLinkSpec::WriteToAppleEvent
- //------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODLinkSpecWriteToAppleEvent(ODLinkSpec *somSelf, Environment *ev,
- AppleEvent* theAppleEvent)
- {
- ODLinkSpecData *somThis = ODLinkSpecGetData(somSelf);
- ODLinkSpecMethodDebug("ODLinkSpec","WriteToAppleEvent");
-
- SOM_TRY
-
- OSErr error;
- ODPart* part = somSelf->GetPart(ev);
- ODByteArray partData = somSelf->GetPartData(ev);
-
- ODULong version = kLinkSpecVersion;
- error = AEPutParamPtr((AppleEvent*) theAppleEvent, kODLinkSpecVersionKey, typeLongInteger,
- &version, sizeof(version));
-
- if ( error == noErr )
- error = AEPutParamPtr((AppleEvent*) theAppleEvent, keyProcessSerialNumber, typeProcessSerialNumber,
- &_fProcessID, sizeof(_fProcessID));
-
- if ( error == noErr )
- error = AEPutParamPtr((AppleEvent*) theAppleEvent, kODProcessLaunchDateKey, typeLongInteger,
- &_fProcessLaunchDate, sizeof(_fProcessLaunchDate));
-
- if ( error == noErr )
- error = AEPutParamPtr((AppleEvent*) theAppleEvent, kODSourcePartKey, typeLongInteger,
- &part, sizeof(part));
-
- if ( error == noErr )
- error = AEPutParamPtr((AppleEvent*) theAppleEvent, kODLinkSpecDataSizeKey, typeLongInteger,
- &partData._length, sizeof(ODULong));
-
- if ( (error == noErr) && (partData._length > 0) )
- error = AEPutParamPtr((AppleEvent*) theAppleEvent, kODLinkSpecDataKey, typeChar /* ••• need better type here •••• */,
- partData._buffer, partData._length);
-
- DisposeByteArrayStruct(partData);
-
- THROW_IF_ERROR(error);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // ODLinkSpec::ReadFromAppleEvent
- //------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODLinkSpecReadFromAppleEvent(ODLinkSpec *somSelf, Environment *ev,
- AppleEvent* theAppleEvent)
- {
- ODLinkSpecData *somThis = ODLinkSpecGetData(somSelf);
- ODLinkSpecMethodDebug("ODLinkSpec","ReadFromAppleEvent");
-
- SOM_CATCH return;
-
- /* Moved from somInit. SOM itself sets fields to zero
- _fProcessLaunchDate = 0;
- _fProcessID.lowLongOfPSN = kNoProcess;
- _fProcessID.highLongOfPSN = 0;
- */
-
- OSErr result;
- DescType returnedType;
- Size actualSize;
- ODPart* part;
- ODByteArray partData;
- ProcessSerialNumber processID;
- ODULong processLaunchDate;
- ODULong dataSize;
-
- result = AEGetParamPtr((AppleEvent*) theAppleEvent, keyProcessSerialNumber, typeProcessSerialNumber, &returnedType,
- &processID, sizeof(processID), &actualSize);
- THROW_IF_ERROR(result);
-
- result = AEGetParamPtr((AppleEvent*) theAppleEvent, kODProcessLaunchDateKey, typeLongInteger, &returnedType,
- &processLaunchDate, sizeof(processLaunchDate), &actualSize);
- THROW_IF_ERROR(result);
-
- result = AEGetParamPtr((AppleEvent*) theAppleEvent, kODSourcePartKey, typeLongInteger, &returnedType,
- &part, sizeof(part), &actualSize);
- THROW_IF_ERROR(result);
-
- result = AEGetParamPtr((AppleEvent*) theAppleEvent, kODLinkSpecDataSizeKey, typeLongInteger, &returnedType,
- &dataSize, sizeof(ODULong), &actualSize);
- THROW_IF_ERROR(result);
-
- partData = CreateEmptyByteArrayStruct(dataSize);
-
- TRY
- if ( dataSize > 0 )
- {
- result = AEGetParamPtr((AppleEvent*) theAppleEvent, kODLinkSpecDataKey, typeChar, &returnedType,
- partData._buffer, dataSize, &actualSize);
- THROW_IF_ERROR(result);
- partData._length = dataSize;
- }
- somSelf->InitBaseLinkSpec(ev, part, &partData);
- CATCH_ALL
- DisposeByteArrayStruct(partData);
- RERAISE;
- ENDTRY
-
- DisposeByteArrayStruct(partData);
-
- _fProcessID = processID;
- _fProcessLaunchDate = processLaunchDate;
- }
-